#pragma strict
//speed:float = .04;
static var fired: int = 0;
var xStart:float;
var yStart:float;

var pointValue: int;
var enemyController: GameObject;
var enemySettings: EnemySettings;
var enemyShoots: int = 90;
var randomValue: int;
var projectile : Transform;
var fires : boolean = true;

function Start () {
	xStart = transform.position.x;
	yStart = transform.position.y;
	
	if(transform.position.y < 14){
		pointValue = 10;
		return;
	}
	else if(transform.position.y < 20){
		pointValue = 20;
		return;
	}
	else {
		pointValue = 40;
	}
	
	enemyController = GameObject.Find("EnemyController");
	enemySettings = enemyController.GetComponent("EnemySettings");
	

}

function Update () {
	enemyShoots = Mathf.Min(enemyShoots, transform.position.y);
	randomValue = Random.Range(4, 10);
	transform.position.x += EnemySettings.speed;
	if(transform.position.x - GameObject.Find("ShipPrefab").transform.position.x <= 1){
		randomValue = 5;
	}

	enemyShoots = Mathf.Min(enemyShoots, transform.position.y);
	if(fired <= 1){
		if(enemyShoots == transform.position.y && randomValue == 5){
			var clone : Transform;
       		clone = Instantiate(projectile, transform.position, transform.rotation);
			clone.rigidbody.velocity = transform.TransformDirection (Vector3.down * 10);
			fired++;
		}
	}
}